#include "gui.h"

//constructor
UI::UI(){
    //set class vars
    lenPrompt = 0;
    lastlen = 0;
    strPrompt.clear();
}

//destructor
UI::~UI(){
    //no memory assigned, nothing to destroy
}

/** @fn     UI::set(string& prompt)
    @brief  sets the UI output data
    @param  prompt  the string containing the data for the textual UI
    @return void
    */
void UI::set(string& prompt){
    strPrompt = prompt;
    lastlen = lenPrompt;
    lenPrompt = prompt.length();
}

/** @fn     UI::update(string& prompt)
    @brief  refreshes the output terminal
    @param  prompt the content of the prompt to be written
    @return void
    */
void UI::update(string& prompt){
    //set prompt data
    set(prompt);

    //remove last line
    for(int y = 0; y < lastlen; y++){
        cout << "\b \b";
    }

    //output prompt data
    cout << strPrompt;
}

/** @fn     UI::awaitinput()
    @brief  awaits the user input
    @param  none
    @return the character entered by the user
    */
int UI::awaitinput(){
    char x = getch();
    return ((int) x);
}
